//---------------------------------------------------------------------------- Strict
'use strict'
//---------------------------------------------------------------------------- Package
const log4js = require('log4js')
//---------------------------------------------------------------------------- Library
const time = require('../library/string/time')
//---------------------------------------------------------------------------- Configure
log4js.configure({
  appenders: [

    // 访问类
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/req.get.log', category: 'get' },
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/req.post.log', category: 'post' },
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/req.put.log', category: 'put' },
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/req.delete.log', category: 'delete' },

    // 程序类
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/pro.info.log', category: 'info' },
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/pro.warn.log', category: 'warn' },
    { type: 'file', filename: 'log/' + time.format('YYYY-MM-dd') + '/pro.error.log', category: 'error' }
  ]
})
//---------------------------------------------------------------------------- Global Object
global.log = {

  // 访问类
  get: function (msg) {
    let log = log4js.getLogger('get')
    log.info(msg)
  },
  post: function (msg) {
    let log = log4js.getLogger('post')
    log.info(msg)
  },
  put: function (msg) {
    let log = log4js.getLogger('put')
    log.info(msg)
  },
  delete: function (msg) {
    let log = log4js.getLogger('delete')
    log.info(msg)
  },

  // 程序类
  info: function (msg) {
    let log = log4js.getLogger('info')
    log.info(msg)
  },
  warn: function (msg) {
    let log = log4js.getLogger('warn')
    log.warn(msg)
  },
  error: function (msg) {
    let log = log4js.getLogger('error')
    log.error(msg)
  }
}
